package com.gedeshidai.shumadevelop.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gedeshidai.shumadevelop.common.BaseResponse;
import com.gedeshidai.shumadevelop.common.ErrorCode;
import com.gedeshidai.shumadevelop.common.ResultUtils;
import com.gedeshidai.shumadevelop.exception.BusinessException;
import com.gedeshidai.shumadevelop.model.dto.product.*;
import com.gedeshidai.shumadevelop.model.vo.ProductVO;
import com.gedeshidai.shumadevelop.model.vo.UserVO;
import com.gedeshidai.shumadevelop.service.ProductService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/product")
public class ProductController {
    @Resource
    private ProductService productService;
    @GetMapping("/select")
    public BaseResponse<Page<ProductVO>> SelectShoppingsDetailsList(ProductSelectRequest productSelectRequest, HttpServletRequest request){
        if (productSelectRequest ==null||request==null){
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        return productService.SelectShoppingsDetailsList(productSelectRequest,request);
    }

    /**
     * 添加代理人
     * @param addProxyRequest
     * @return
     */
    @PostMapping("/add")
    public BaseResponse addProxy(@RequestBody AddProxyRequest addProxyRequest){
        if (addProxyRequest==null){
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        productService.addProxy(addProxyRequest.getUserAccount(),addProxyRequest.getId());
        return ResultUtils.success(true);
    }
    /**
     * 从基本商品表中删除的代理人
     * @param detailDeleteRequest
     * @return
     */
    @PostMapping("/delete")
    public BaseResponse deleteProxys(@RequestBody DetailDeleteRequest detailDeleteRequest){
        if (detailDeleteRequest==null){
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        productService.deleteProxys(detailDeleteRequest.getProxys(),detailDeleteRequest.getId());
        return ResultUtils.success(true);
    }
    /**
     * 根据商品id查询代理人和代理人id
     * @param productProxyRequest
     * @return
     */
    @PostMapping("/proxy")
    public BaseResponse<Page<UserVO>>getProxysById(@RequestBody ProductProxyRequest productProxyRequest) {
        if (productProxyRequest ==null){
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        return productService.getProxysById(productProxyRequest);
    }
}
